package boogui.movie;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JSeparator;
import javax.swing.KeyStroke;

import boogui.member.MemberService;
import boogui.member.UserVO;

public class S_MovieMenu extends JMenuBar {
	
	private JMenu mnMember = null;
	private JMenu mnHelp = null;
	private JMenu mnAdmin = null;	
	private MovieActionListener mal = null;
	private MemberService ms = null;
	
	public S_MovieMenu(JFrame p, UserVO u) {		
		mal = new MovieActionListener(p, u);		
		ms = new MemberService();
		makeMenu(u);
		makeMenuItem();
		addShortCut();
		addMenu();		
	}

	private void makeMenu(UserVO u) {
		mnMember = new JMenu(" 회 원 (M) ");
		mnHelp = new JMenu(" 도움말 (H) ");
		mnAdmin = new JMenu(" 관리자 (A) ");		
		if (ms.isAdminSvc(u)) {
			mnAdmin.setVisible(true);
		} else {
			mnAdmin.setVisible(false);
		}
		
	}
	
	private void addShortCut() {
		mnMember.setMnemonic(KeyEvent.VK_M);		
		mnHelp.setMnemonic(KeyEvent.VK_H);
		mnAdmin.setMnemonic(KeyEvent.VK_A);		
	}
	
	private void addMenu() {
		add(mnMember);
		add(mnHelp);
		add(mnAdmin);
	}
	
	private JMenuItem makeMenuItems(String text, String img, int skey, boolean off, int akey) {
		String icon = null;
		if(img != null){
			icon = "/images/menu/" + img + ".png";
		}
		
		JMenuItem mnitem = null;
		try {
			mnitem = new JMenuItem(text, new ImageIcon(getClass().getResource(icon)));
		} catch (Exception ex) {
			mnitem = new JMenuItem(text);
		}
		
		mnitem.setEnabled(off);
		mnitem.setMnemonic(skey);
		mnitem.setAccelerator(KeyStroke.getKeyStroke(akey, ActionEvent.CTRL_MASK));	// 단축키				
		
		mnitem.addActionListener(mal); ///////////////////////////////// 회원정보 수정
		mnitem.setActionCommand(img);////////////////////////////////////회원정보 수정
		return mnitem;
		
		
	}
	
	private void makeMenuItem() {	
		mnMember.add(makeMenuItems("예매 정보 확인 (C)      ", "rcheck", KeyEvent.VK_C, true, KeyEvent.VK_C));	
		mnMember.add(new JSeparator());
		mnMember.add(makeMenuItems("회원 정보 수정 (I)", "user", KeyEvent.VK_I, true, KeyEvent.VK_I));
		mnMember.add(new JSeparator());		
		mnMember.add(makeMenuItems("종 료 (X)", "exit", KeyEvent.VK_X, true, KeyEvent.VK_X));

	//	mnHelp.add(makeMenuItems("도 움 말 (H)       ", "help", KeyEvent.VK_H, true, KeyEvent.VK_H));
	//	mnHelp.add(new JSeparator());
		mnHelp.add(makeMenuItems("정 보 (A)", "about", KeyEvent.VK_A, true, KeyEvent.VK_A));
		
		mnAdmin.add(makeMenuItems("회원 관리 (M)", "member", KeyEvent.VK_M, true, KeyEvent.VK_M));
		mnAdmin.add(new JSeparator());
		mnAdmin.add(makeMenuItems("영화 등록 (R)", "movie", KeyEvent.VK_R, true, KeyEvent.VK_R));
		mnAdmin.add(makeMenuItems("상영 정보 등록 (S)        ", "showing", KeyEvent.VK_S, true, KeyEvent.VK_S));		
		mnAdmin.add(makeMenuItems("영화 삭제 (D)", "delete", KeyEvent.VK_D, true, KeyEvent.VK_D));		
	}
}
